<?php

namespace Admin\Controller;

use Think\Controller;
use Common\Util\UploadHandler;

class MessageTemplateController extends BaseController {
	
	public function index() {
		$Model = D ( 'MessageTemplate' );
		
		$list = $Model->select ();
		
		$this->assign ( 'list', $list );
		$this->display ();
	}
	
	public function add() {
		if (! IS_POST) {
			$this->display ();
		} else {
			$Model = D ( 'MessageTemplate' );
			
			$data = I ( 'post.' );
			$c_id = 0;
			$data ['create_time'] = time();
			if ($c_id = $Model->add ( $data )) {
				$this->success ( '添加成功', U ( '/Admin/MessageTemplate/index' ) );
			} else {
				$this->error ( '添加失败' );
			}
		}
	}
	
	public function edit() {
		if (! IS_POST) {
			$id = I ( 'get.id' );
			$Model = D ( 'MessageTemplate' );
			$item = $Model->where(array('id' => $id))->find();
			$this->assign ( 'item', $item );
			$this->display ();
		} else {
			$Model = D ( 'MessageTemplate' );
			$data = I ('post.');
			$data ['updated_time'] = time();
			if ($Model->save($data)) {
				$this->success ( '修改成功', U ( '/Admin/MessageTemplate/index' ) );
			} else {
				$this->error ( $Model->getError () );
			}
		}
	}
	
	public function delete() {
		
	}
}